# -*- coding: utf-8 -*-

import sys
from PyQt4 import QtCore, QtGui
from core import uicomponents, init_modules, constants, log


class HelpForm(QtGui.QMainWindow):
	def __init__(self,parent=None):
		QtGui.QMainWindow.__init__(self,parent)
		browser = QtGui.QTextBrowser(self)
		browser.setSource(QtCore.QUrl.fromLocalFile(constants.app_path+"\Helps\index.html"))
		self.setCentralWidget(browser)
		self.resize(600,500)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,800,600).size()).expandedTo(MainWindow.minimumSizeHint()))

	log.logger.debug('Setting default font...')
	MainWindow.setFont(uicomponents.SharedUi.defaultFont)


        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        MainWindow.setCentralWidget(self.centralwidget)


	self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.menubar = QtGui.QMenuBar(MainWindow)
        MainWindow.setMenuBar(self.menubar)

	self.exitAction = QtGui.QAction(QtGui.QIcon('images/exit.gif'), u'خروج',None)
	self.exitAction.setShortcut('Ctrl+X')
	self.exitAction.setStatusTip(u'خروج از برنامه')
	QtCore.QObject.connect(self.exitAction, QtCore.SIGNAL("triggered()"), sys.exit)
	
	self.fileMenu = QtGui.QMenu(u'پرونده')
	self.fileMenu.addAction(self.exitAction)
	self.menubar.addMenu(self.fileMenu)

	self.menubar.addMenu(uicomponents.SharedUi.docablesMenu)
	log.logger.info('Adding applications in menu')
	for _app in uicomponents.SharedUi.applications.items():
		log.logger.info('	%s...' % _app[0])
		_app[1]['action'] = QtGui.QAction(MainWindow)
		_app[1]['action'].setText(_app[1]['name'])
		_app[1]['action'].setShortcut(_app[1]['shortcut'])
		QtCore.QObject.connect(_app[1]['action'],QtCore.SIGNAL('triggered()'),_app[1]['actionSlot'])
		uicomponents.SharedUi.docablesMenu.addAction(_app[1]['action'])

	#ToDo
	helpForm = HelpForm()
	self.helpAction = QtGui.QAction(QtGui.QIcon("images/help.gif"),u'راهنما',None)
	self.helpAction.setShortcut('Ctrl+H')
	self.helpAction.setStatusTip(u'راهنماي نرم افزار')
	QtCore.QObject.connect(self.helpAction,QtCore.SIGNAL("triggered()"),helpForm.showMaximized)
	self.menubar.addAction(self.helpAction)


	self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "برنامه تحقیقات", None, QtGui.QApplication.UnicodeUTF8))



